package com.link.base.base.language.controller;

import com.link.base.base.language.model.LangModules;
import com.link.base.base.language.service.LangModulesService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.ReturnCodeConstants;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.KeyGenerateService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 语言包模块
 *
 * @author 阳晓琳
 * @date 2020-08-27 10:59:45
 */
@Controller
@RequestMapping("/link/langModules")
public class LangModulesController extends BasicController<LangModules> {
    private static final Logger logger = LogManager.getLogger(LangModulesController.class);

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private LangModulesService langModulesService;

    @Override
    public BasicService<LangModules> getBasicService() throws Exception {
        return langModulesService;
    }

    @RequestMapping(value = "/deleteByIdCascade")
    @ResponseBody
    public Map<String, Object> deleteByIdCascade(@JsonParam LangModules entity, HttpSession session,
                                                 HttpServletRequest request, HttpServletResponse response) {
        logger.info("删除一条列表信息...");
        Map<String, Object> result = new HashMap<>(4);
        try {
            beforDelete(entity, request);
            checkData(entity, request);
            if (!checkExistDataCache("base", session, entity)) {
                throw new BasicServiceException("非法删除数据！");
            }
            langModulesService.deleteByIdCascade(entity);
            result.put("success", true);
            result.put("code", ReturnCodeConstants.SUCCESS);
        } catch (BasicServiceException e) {
            logger.error("BasicController捕获异常: ", e);
            result.put("success", false);
            result.put("result", e.getMessage());
            result.put("detailMessage", e.getDetailMessage());
            result.put("code", e.getCode());
        } catch (Exception e) {
            logger.error("BasicController捕获异常: ", e);
            result.put("success", false);
            result.put("result", e.getMessage());
            result.put("code", ReturnCodeConstants.EXCEPTION);
        }
        return result;
    }
}
